package com.limao.Tool;


import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import com.limao.DBDataClass.CrowdSysProjectCutClass;
import com.limao.DbConnection.DbConnectionManager;
import com.limao.Model.LzPluginException;

public class cutRmb {
	

	//邀请　提成计算  
	public static float getInviteCutRmb(int parentLevel) throws LzPluginException
	{
		float cutRmb=0;
		float total= CacheClass.getFloatValue(CacheClass.getSYS_BaseDataCacheManager().Load_Param("invite_totalrmb").trim());
		int type=CacheClass.getIntValue(CacheClass.getSYS_BaseDataCacheManager().Load_Param("invite_type").trim());
		
		switch(parentLevel)
		{
		case 0:
			if(type==1)
				cutRmb=CacheClass.getFloatValue(CacheClass.getSYS_BaseDataCacheManager().Load_Param("invite_general_0").trim());
			else
				cutRmb=(total/100)*CacheClass.getFloatValue(CacheClass.getSYS_BaseDataCacheManager().Load_Param("invite_general_0_rate").trim());
			break;
		case 1:
			if(type==1)
				cutRmb=CacheClass.getFloatValue(CacheClass.getSYS_BaseDataCacheManager().Load_Param("invite_general_1").trim());
			else
				cutRmb=(total/100)*CacheClass.getFloatValue(CacheClass.getSYS_BaseDataCacheManager().Load_Param("invite_general_1_rate").trim());
			break;		
		case 2:
			if(type==1)
				cutRmb=CacheClass.getFloatValue(CacheClass.getSYS_BaseDataCacheManager().Load_Param("invite_general_2").trim());
			else
				cutRmb=(total/100)*CacheClass.getFloatValue(CacheClass.getSYS_BaseDataCacheManager().Load_Param("invite_general_2_rate").trim());
			break;		
		case 3:
			if(type==1)
				cutRmb=CacheClass.getFloatValue(CacheClass.getSYS_BaseDataCacheManager().Load_Param("invite_general_3").trim());
			else
				cutRmb=(total/100)*CacheClass.getFloatValue(CacheClass.getSYS_BaseDataCacheManager().Load_Param("invite_general_3_rate").trim());
			break;			
		default:
			cutRmb=0;
		}
		
		
		return cutRmb;
	}
	
	
	//邀请　给上级的提成　是否属于冻结
	public static int isFreezeInviteCutRmb(int toUserid) throws LzPluginException
	{
		//UserAuthDataClass tmp=CrowdUserAuthCache.getInstance().getUser(toUserid);
		//int manTotal=CacheClass.getIntValue(tmp.now_normalmannum);
		
		int manTotal=-1;
		Connection con = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		try {
			int mannum_day=CacheClass.getIntValue(CacheClass.getSYS_BaseDataCacheManager().Load_Param("mannum_day").trim());
			if(mannum_day==0) 
				mannum_day=30;
			long t2=mannum_day*24;
			t2=60*60*1000*t2;
			long nowtime=CacheClass.getTime();
			nowtime=nowtime-t2;

			con = DbConnectionManager.getConnection();
			pstmt = con.prepareStatement("select COUNT(id) as num from cd_user_parent where ((pid0=? or pid1=? or pid2=? ) and time>?) ");
			pstmt.setInt(1, toUserid);
			pstmt.setInt(2, toUserid);
			pstmt.setInt(3, toUserid);
			pstmt.setLong(4, nowtime);
			
			rs = pstmt.executeQuery();
			if (rs.next()) {
				manTotal=rs.getInt("num");
			}

		} catch (Exception e) {
			manTotal=-1;
			e.printStackTrace();
		} finally {
			DbConnectionManager.closeConnection(rs, pstmt, con);
		}
		
 
		if(manTotal<0) return 0; //冻结
		
		if(manTotal<CacheClass.getFloatValue(CacheClass.getSYS_BaseDataCacheManager().Load_Param("invite_limitmannums").trim()))
			return 1; //正常
		else
			return 0; //冻结

	}
		
	
	
	
	//购买　提成计算(现金)
	public static float getBuyCutRmb(float totalRmb,int goodsnum,int parentLevel,int viplevel,CrowdSysProjectCutClass goodscut) throws LzPluginException
	{
		float cutRmb=0;

		int type=CacheClass.getIntValue(goodscut.regular_type);
		
		switch(parentLevel)
		{
		case 0:
			switch(viplevel)
			{
			case 0: //非vip
				if(type==1)
					cutRmb=goodsnum*CacheClass.getFloatValue(goodscut.regular_scale0_0.trim());
				else
					cutRmb=totalRmb*CacheClass.getFloatValue(goodscut.regular_scale0_0.trim())/100;
				break;
			case 1: //vip1
				if(type==1)
					cutRmb=goodsnum*CacheClass.getFloatValue(goodscut.regular_scale0_1.trim());
				else
					cutRmb=totalRmb*CacheClass.getFloatValue(goodscut.regular_scale0_1.trim())/100;
				break;
			case 2: //vip2
				if(type==1)
					cutRmb=goodsnum*CacheClass.getFloatValue(goodscut.regular_scale0_2.trim());
				else
					cutRmb=totalRmb*CacheClass.getFloatValue(goodscut.regular_scale0_2.trim())/100;
				break;
			case 3: //vip3
				if(type==1)
					cutRmb=goodsnum*CacheClass.getFloatValue(goodscut.regular_scale0_3.trim());
				else
					cutRmb=totalRmb*CacheClass.getFloatValue(goodscut.regular_scale0_3.trim())/100;
				break;
			case 4: //vip4
				if(type==1)
					cutRmb=goodsnum*CacheClass.getFloatValue(goodscut.regular_scale0_4.trim());
				else
					cutRmb=totalRmb*CacheClass.getFloatValue(goodscut.regular_scale0_4.trim())/100;
				break;
			case 5: //vip5
				if(type==1)
					cutRmb=goodsnum*CacheClass.getFloatValue(goodscut.regular_scale0_5.trim());
				else
					cutRmb=totalRmb*CacheClass.getFloatValue(goodscut.regular_scale0_5.trim())/100;
				break;
			}

			break;
		case 1:
			switch(viplevel)
			{
			case 0: //非vip
				if(type==1)
					cutRmb=goodsnum*CacheClass.getFloatValue(goodscut.regular_scale1_0.trim());
				else
					cutRmb=totalRmb*CacheClass.getFloatValue(goodscut.regular_scale1_0.trim())/100;
				break;
			case 1: //vip1
				if(type==1)
					cutRmb=goodsnum*CacheClass.getFloatValue(goodscut.regular_scale1_1.trim());
				else
					cutRmb=totalRmb*CacheClass.getFloatValue(goodscut.regular_scale1_1.trim())/100;
				break;
			case 2: //vip2
				if(type==1)
					cutRmb=goodsnum*CacheClass.getFloatValue(goodscut.regular_scale1_2.trim());
				else
					cutRmb=totalRmb*CacheClass.getFloatValue(goodscut.regular_scale1_2.trim())/100;
				break;
			case 3: //vip3
				if(type==1)
					cutRmb=goodsnum*CacheClass.getFloatValue(goodscut.regular_scale1_3.trim());
				else
					cutRmb=totalRmb*CacheClass.getFloatValue(goodscut.regular_scale1_3.trim())/100;
				break;
			case 4: //vip4
				if(type==1)
					cutRmb=goodsnum*CacheClass.getFloatValue(goodscut.regular_scale1_4.trim());
				else
					cutRmb=totalRmb*CacheClass.getFloatValue(goodscut.regular_scale1_4.trim())/100;
				break;
			case 5: //vip5
				if(type==1)
					cutRmb=goodsnum*CacheClass.getFloatValue(goodscut.regular_scale1_5.trim());
				else
					cutRmb=totalRmb*CacheClass.getFloatValue(goodscut.regular_scale1_5.trim())/100;
				break;
			}
			break;	
		case 2:
			switch(viplevel)
			{
			case 0: //非vip
				if(type==1)
					cutRmb=goodsnum*CacheClass.getFloatValue(goodscut.regular_scale2_0.trim());
				else
					cutRmb=totalRmb*CacheClass.getFloatValue(goodscut.regular_scale2_0.trim())/100;
				break;
			case 1: //vip1
				if(type==1)
					cutRmb=goodsnum*CacheClass.getFloatValue(goodscut.regular_scale2_1.trim());
				else
					cutRmb=totalRmb*CacheClass.getFloatValue(goodscut.regular_scale2_1.trim())/100;
				break;
			case 2: //vip2
				if(type==1)
					cutRmb=goodsnum*CacheClass.getFloatValue(goodscut.regular_scale2_2.trim());
				else
					cutRmb=totalRmb*CacheClass.getFloatValue(goodscut.regular_scale2_2.trim())/100;
				break;
			case 3: //vip3
				if(type==1)
					cutRmb=goodsnum*CacheClass.getFloatValue(goodscut.regular_scale2_3.trim());
				else
					cutRmb=totalRmb*CacheClass.getFloatValue(goodscut.regular_scale2_3.trim())/100;
				break;
			case 4: //vip4
				if(type==1)
					cutRmb=goodsnum*CacheClass.getFloatValue(goodscut.regular_scale2_4.trim());
				else
					cutRmb=totalRmb*CacheClass.getFloatValue(goodscut.regular_scale2_4.trim())/100;
				break;
			case 5: //vip5
				if(type==1)
					cutRmb=goodsnum*CacheClass.getFloatValue(goodscut.regular_scale2_5.trim());
				else
					cutRmb=totalRmb*CacheClass.getFloatValue(goodscut.regular_scale2_5.trim())/100;
				break;
			}
			break;			
		case 3:
			switch(viplevel)
			{
			case 0: //非vip
				if(type==1)
					cutRmb=goodsnum*CacheClass.getFloatValue(goodscut.regular_scale3_0.trim());
				else
					cutRmb=totalRmb*CacheClass.getFloatValue(goodscut.regular_scale3_0.trim())/100;
				break;
			case 1: //vip1
				if(type==1)
					cutRmb=goodsnum*CacheClass.getFloatValue(goodscut.regular_scale3_1.trim());
				else
					cutRmb=totalRmb*CacheClass.getFloatValue(goodscut.regular_scale3_1.trim())/100;
				break;
			case 2: //vip2
				if(type==1)
					cutRmb=goodsnum*CacheClass.getFloatValue(goodscut.regular_scale3_2.trim());
				else
					cutRmb=totalRmb*CacheClass.getFloatValue(goodscut.regular_scale3_2.trim())/100;
				break;
			case 3: //vip3
				if(type==1)
					cutRmb=goodsnum*CacheClass.getFloatValue(goodscut.regular_scale3_3.trim());
				else
					cutRmb=totalRmb*CacheClass.getFloatValue(goodscut.regular_scale3_3.trim())/100;
				break;
			case 4: //vip4
				if(type==1)
					cutRmb=goodsnum*CacheClass.getFloatValue(goodscut.regular_scale3_4.trim());
				else
					cutRmb=totalRmb*CacheClass.getFloatValue(goodscut.regular_scale3_4.trim())/100;
				break;
			case 5: //vip5
				if(type==1)
					cutRmb=goodsnum*CacheClass.getFloatValue(goodscut.regular_scale3_5.trim());
				else
					cutRmb=totalRmb*CacheClass.getFloatValue(goodscut.regular_scale3_5.trim())/100;
				break;
			}
			break;			
		default:
			cutRmb=0;
		}
		
		return cutRmb;
	}
	
	//购买　提成计算(瓶数)
	public static float getBuyCutNum(float totalRmb,int goodsnum,int parentLevel,int viplevel,CrowdSysProjectCutClass goodscut) throws LzPluginException
	{
		float cutRmb=0;

		int type=CacheClass.getIntValue(goodscut.regular_type);
		switch(parentLevel)
		{
		case 0:
			switch(viplevel)
			{
			case 0: //非vip
				if(type==1)
					cutRmb=goodsnum*CacheClass.getFloatValue(goodscut.regular_num0_0.trim());
				else
					cutRmb=totalRmb*CacheClass.getFloatValue(goodscut.regular_num0_0.trim())/100;
				break;
			case 1: //vip1
				if(type==1)
					cutRmb=goodsnum*CacheClass.getFloatValue(goodscut.regular_num0_1.trim());
				else
					cutRmb=totalRmb*CacheClass.getFloatValue(goodscut.regular_num0_1.trim())/100;
				break;
			case 2: //vip2
				if(type==1)
					cutRmb=goodsnum*CacheClass.getFloatValue(goodscut.regular_num0_2.trim());
				else
					cutRmb=totalRmb*CacheClass.getFloatValue(goodscut.regular_num0_2.trim())/100;
				break;
			case 3: //vip3
				if(type==1)
					cutRmb=goodsnum*CacheClass.getFloatValue(goodscut.regular_num0_3.trim());
				else
					cutRmb=totalRmb*CacheClass.getFloatValue(goodscut.regular_num0_3.trim())/100;
				break;
			case 4: //vip4
				if(type==1)
					cutRmb=goodsnum*CacheClass.getFloatValue(goodscut.regular_num0_4.trim());
				else
					cutRmb=totalRmb*CacheClass.getFloatValue(goodscut.regular_num0_4.trim())/100;
				break;
			case 5: //vip5
				if(type==1)
					cutRmb=goodsnum*CacheClass.getFloatValue(goodscut.regular_num0_5.trim());
				else
					cutRmb=totalRmb*CacheClass.getFloatValue(goodscut.regular_num0_5.trim())/100;
				break;
			}

			break;
		case 1:
			switch(viplevel)
			{
			case 0: //非vip
				if(type==1)
					cutRmb=goodsnum*CacheClass.getFloatValue(goodscut.regular_num1_0.trim());
				else
					cutRmb=totalRmb*CacheClass.getFloatValue(goodscut.regular_num1_0.trim())/100;
				break;
			case 1: //vip1
				if(type==1)
					cutRmb=goodsnum*CacheClass.getFloatValue(goodscut.regular_num1_1.trim());
				else
					cutRmb=totalRmb*CacheClass.getFloatValue(goodscut.regular_num1_1.trim())/100;
				break;
			case 2: //vip2
				if(type==1)
					cutRmb=goodsnum*CacheClass.getFloatValue(goodscut.regular_num1_2.trim());
				else
					cutRmb=totalRmb*CacheClass.getFloatValue(goodscut.regular_num1_2.trim())/100;
				break;
			case 3: //vip3
				if(type==1)
					cutRmb=goodsnum*CacheClass.getFloatValue(goodscut.regular_num1_3.trim());
				else
					cutRmb=totalRmb*CacheClass.getFloatValue(goodscut.regular_num1_3.trim())/100;
				break;
			case 4: //vip4
				if(type==1)
					cutRmb=goodsnum*CacheClass.getFloatValue(goodscut.regular_num1_4.trim());
				else
					cutRmb=totalRmb*CacheClass.getFloatValue(goodscut.regular_num1_4.trim())/100;
				break;
			case 5: //vip5
				if(type==1)
					cutRmb=goodsnum*CacheClass.getFloatValue(goodscut.regular_num1_5.trim());
				else
					cutRmb=totalRmb*CacheClass.getFloatValue(goodscut.regular_num1_5.trim())/100;
				break;
			}
			break;	
		case 2:
			switch(viplevel)
			{
			case 0: //非vip
				if(type==1)
					cutRmb=goodsnum*CacheClass.getFloatValue(goodscut.regular_num2_0.trim());
				else
					cutRmb=totalRmb*CacheClass.getFloatValue(goodscut.regular_num2_0.trim())/100;
				break;
			case 1: //vip1
				if(type==1)
					cutRmb=goodsnum*CacheClass.getFloatValue(goodscut.regular_num2_1.trim());
				else
					cutRmb=totalRmb*CacheClass.getFloatValue(goodscut.regular_num2_1.trim())/100;
				break;
			case 2: //vip2
				if(type==1)
					cutRmb=goodsnum*CacheClass.getFloatValue(goodscut.regular_num2_2.trim());
				else
					cutRmb=totalRmb*CacheClass.getFloatValue(goodscut.regular_num2_2.trim())/100;
				break;
			case 3: //vip3
				if(type==1)
					cutRmb=goodsnum*CacheClass.getFloatValue(goodscut.regular_num2_3.trim());
				else
					cutRmb=totalRmb*CacheClass.getFloatValue(goodscut.regular_num2_3.trim())/100;
				break;
			case 4: //vip4
				if(type==1)
					cutRmb=goodsnum*CacheClass.getFloatValue(goodscut.regular_num2_4.trim());
				else
					cutRmb=totalRmb*CacheClass.getFloatValue(goodscut.regular_num2_4.trim())/100;
				break;
			case 5: //vip5
				if(type==1)
					cutRmb=goodsnum*CacheClass.getFloatValue(goodscut.regular_num2_5.trim());
				else
					cutRmb=totalRmb*CacheClass.getFloatValue(goodscut.regular_num2_5.trim())/100;
				break;
			}
			break;			
		case 3:
			switch(viplevel)
			{
			case 0: //非vip
				if(type==1)
					cutRmb=goodsnum*CacheClass.getFloatValue(goodscut.regular_num3_0.trim());
				else
					cutRmb=totalRmb*CacheClass.getFloatValue(goodscut.regular_num3_0.trim())/100;
				break;
			case 1: //vip1
				if(type==1)
					cutRmb=goodsnum*CacheClass.getFloatValue(goodscut.regular_num3_1.trim());
				else
					cutRmb=totalRmb*CacheClass.getFloatValue(goodscut.regular_num3_1.trim())/100;
				break;
			case 2: //vip2
				if(type==1)
					cutRmb=goodsnum*CacheClass.getFloatValue(goodscut.regular_num3_2.trim());
				else
					cutRmb=totalRmb*CacheClass.getFloatValue(goodscut.regular_num3_2.trim())/100;
				break;
			case 3: //vip3
				if(type==1)
					cutRmb=goodsnum*CacheClass.getFloatValue(goodscut.regular_num3_3.trim());
				else
					cutRmb=totalRmb*CacheClass.getFloatValue(goodscut.regular_num3_3.trim())/100;
				break;
			case 4: //vip4
				if(type==1)
					cutRmb=goodsnum*CacheClass.getFloatValue(goodscut.regular_num3_4.trim());
				else
					cutRmb=totalRmb*CacheClass.getFloatValue(goodscut.regular_num3_4.trim())/100;
				break;
			case 5: //vip5
				if(type==1)
					cutRmb=goodsnum*CacheClass.getFloatValue(goodscut.regular_num3_5.trim());
				else
					cutRmb=totalRmb*CacheClass.getFloatValue(goodscut.regular_num3_5.trim())/100;
				break;
			}
			break;			
		default:
			cutRmb=0;
		}
		
		return cutRmb;
	}
		
	
	//购买　提成计算(宝箱)
	public static int getBuyCutRedbag(int parentLevel,int viplevel,CrowdSysProjectCutClass goodscut) throws LzPluginException
	{
		int redbagid=0;

		switch(parentLevel)
		{
		case 0:
			switch(viplevel)
			{
			case 0: //非vip
				redbagid=CacheClass.getIntValue(goodscut.redbagid0_0.trim());
				break;
			case 1: //vip1
				redbagid=CacheClass.getIntValue(goodscut.redbagid0_1.trim());
				break;
			case 2: //vip2
				redbagid=CacheClass.getIntValue(goodscut.redbagid0_2.trim());
				break;
			case 3: //vip3
				redbagid=CacheClass.getIntValue(goodscut.redbagid0_3.trim());
				break;
			case 4: //vip4
				redbagid=CacheClass.getIntValue(goodscut.redbagid0_4.trim());
				break;
			case 5: //vip5
				redbagid=CacheClass.getIntValue(goodscut.redbagid0_5.trim());
				break;
			}

			break;
		case 1:
			switch(viplevel)
			{
			case 0: //非vip
				redbagid=CacheClass.getIntValue(goodscut.redbagid1_0.trim());
				break;
			case 1: //vip1
				redbagid=CacheClass.getIntValue(goodscut.redbagid1_1.trim());
				break;
			case 2: //vip2
				redbagid=CacheClass.getIntValue(goodscut.redbagid1_2.trim());
				break;
			case 3: //vip3
				redbagid=CacheClass.getIntValue(goodscut.redbagid1_3.trim());
				break;
			case 4: //vip4
				redbagid=CacheClass.getIntValue(goodscut.redbagid1_4.trim());
				break;
			case 5: //vip5
				redbagid=CacheClass.getIntValue(goodscut.redbagid1_5.trim());
				break;
			}

			break;	
		case 2:
			switch(viplevel)
			{
			case 0: //非vip
				redbagid=CacheClass.getIntValue(goodscut.redbagid2_0.trim());
				break;
			case 1: //vip1
				redbagid=CacheClass.getIntValue(goodscut.redbagid2_1.trim());
				break;
			case 2: //vip2
				redbagid=CacheClass.getIntValue(goodscut.redbagid2_2.trim());
				break;
			case 3: //vip3
				redbagid=CacheClass.getIntValue(goodscut.redbagid2_3.trim());
				break;
			case 4: //vip4
				redbagid=CacheClass.getIntValue(goodscut.redbagid2_4.trim());
				break;
			case 5: //vip5
				redbagid=CacheClass.getIntValue(goodscut.redbagid2_5.trim());
				break;
			}

			break;			
		case 3:
			switch(viplevel)
			{
			case 0: //非vip
				redbagid=CacheClass.getIntValue(goodscut.redbagid3_0.trim());
				break;
			case 1: //vip1
				redbagid=CacheClass.getIntValue(goodscut.redbagid3_1.trim());
				break;
			case 2: //vip2
				redbagid=CacheClass.getIntValue(goodscut.redbagid3_2.trim());
				break;
			case 3: //vip3
				redbagid=CacheClass.getIntValue(goodscut.redbagid3_3.trim());
				break;
			case 4: //vip4
				redbagid=CacheClass.getIntValue(goodscut.redbagid3_4.trim());
				break;
			case 5: //vip5
				redbagid=CacheClass.getIntValue(goodscut.redbagid3_5.trim());
				break;
			}

			break;			
		default:
			redbagid=0;
		}
		
		return redbagid;
	}	


	//购买　给上级的提成　是否属于冻结
	public static int isFreezeBuyCutRmb(int toUserid,CrowdSysProjectCutClass goodscut) throws LzPluginException
	{
		//UserAuthDataClass tmp=CrowdUserAuthCache.getInstance().getUser(toUserid);
		//int manTotal=CacheClass.getIntValue(tmp.now_normalmannum);
		
		//if(manTotal<CacheClass.getFloatValue(CacheClass.getSYS_BaseDataCacheManager().Load_Param("buy_limitmannums").trim()))
		//if(manTotal<CacheClass.getFloatValue(goodscut.buy_limitmannums.trim()))
			return 1; //正常
		//else
		//	return 0; //冻结

	}	
	
	
	

}
